package com.kdl.webconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kdl.webconfig.entity.PicConfig;
import com.kdl.webconfig.mapper.PicConfigMapper;
import com.kdl.webconfig.service.IPicConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kdl.webconfig.vo.config.PicConfigQueryReq;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wcj
 * @since 2022-09-04
 */
@Service
public class PicConfigServiceImpl extends ServiceImpl<PicConfigMapper, PicConfig> implements IPicConfigService {

    @Resource
    PicConfigMapper picConfigMapper;

    @Override
    public Page<PicConfig> queryPage(PicConfigQueryReq picConfigReq) {
        Page<PicConfig> picConfigPage = new Page<>(picConfigReq.getPageNo(), picConfigReq.getPageSize());
        QueryWrapper<PicConfig> picConfigQueryWrapper = new QueryWrapper<>();
        picConfigQueryWrapper.lambda().eq(StringUtils.isNotBlank(picConfigReq.getType()),PicConfig::getType,picConfigReq.getType());
        picConfigPage = picConfigMapper.selectPage(picConfigPage, picConfigQueryWrapper);
        return picConfigPage;
    }

    @Override
    public List<PicConfig> queryInfoByTypeAndLanType(String type, Integer lanType) {
        QueryWrapper<PicConfig> picConfigQueryWrapper = new QueryWrapper<>();
        picConfigQueryWrapper.lambda().eq(PicConfig::getType,type);
        picConfigQueryWrapper.lambda().eq(PicConfig::getState,1);
        picConfigQueryWrapper.orderByAsc("sort");
        return picConfigMapper.selectList(picConfigQueryWrapper);
    }
}
